package com.jz.baiduHotSearch.controller;

import com.jz.baiduHotSearch.pojo.HotSearchDO;
import com.jz.baiduHotSearch.service.HotSearchInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "控制层")
@RestController
@RequestMapping("hotSearch")
public class HotSearchController {
    private static final Logger LOGGER = LoggerFactory.getLogger(HotSearchController.class);

    @Autowired
    private HotSearchInfoService hotSearchInfoService;

    /**
     * 新浪热搜
     * @return
     */
    @ApiOperation("A01-手动抓取当前热搜数据【新浪微博】")
    @GetMapping("/xlwb/grabHotSearchData")
    public String grabXlwbHotSearchData() {
        LOGGER.info("开始抓取热搜数据-----------------");
        hotSearchInfoService.xlwbHotSearchInsert();
        LOGGER.info("抓取热搜数据结束-----------------");
        return "成功";
    }

    /**
     * 查询热搜消息
     * @return
     */
    @ApiOperation("A02-最新消息查询【新浪微博】")
    @GetMapping("/findHotInfoList")
    public List<HotSearchDO> findHotInfoList(@RequestParam(value = "keyWord",required = false) String query){
        LOGGER.info("开始查询热搜消息-----------------");
        return hotSearchInfoService.findHotInfoList(query);
    }

    @ApiOperation("A03-历史排名查询【新浪微博】")
    @GetMapping("/findHotInfoSortList")
    public List<HotSearchDO> findHotInfoSortList(@RequestParam(value = "keyWord",required = false) String keyWord,
                                                 @RequestParam(value = "startDate",required = false) String startDate,
                                                 @RequestParam(value = "endDate",required = false) String endDate){
        LOGGER.info("开始查询热搜消息-----------------");
        return hotSearchInfoService.findHotInfoSortList(keyWord,startDate,endDate);
    }


}
